Python implementation code example for single-chain table inversion, single-chain python
You can use cycles or recursion to reverse a single-chain table.1. Cyclic inversion of a single-chain table
In the cyclic method, pre is used to point to the forward node, and cur points
A sequential table of length n is established, then the data elements in the table are reversed, and the original data element sequence in the even if Table is (A0,a1,a2,...,an), then the inverse data element sequence is (AN,AN-1,AN-2,...,A1,A0). (data type is character type)DescriptionThe length of the first behavior order t
, don't just think about 1, that's not good.Note:prefix and want to use LL, however the topic int also no problem#include #include#include#include#includeusing namespaceStd;typedefLong Longll;Const intn=1e7+5, mod=20101009; inlineintRead () {CharC=GetChar (); intx=0, f=1; while(c'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'c'9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn,m;BOOLNotp[n];intP[n];ll S[n],mu[n];voidSieveintN) {mu[1]=1; for(intI=2; i){ if(!notp[i]) p[++p[0]]=
Run the code first.
Void reverse (list * head) {list * P, * TMP; P = head-> next; // P points to the node currently being processed TMP = p-> next; // TMP points to the first node that has not been processed p-> next = NULL; // The first node of the original single linked list will become the last node after the inversion head-> next = P; // insert P = TMP behind the header of the single-chain table; //
In order to represent the logical relationship between each data element AI and its immediate successor element Ai+1, the data AI, in addition to storing its own information, also needs to store a message indicating its immediate successor (i.e., the immediate successor storage location). These two pieces of information form the storage image of the data element AI, known as node (node). n node chains form a linked list, which is a chain-type storage structure for the linear
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.